/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaCategoria.java
 *
 * Created on 05/04/2011, 09:32:38 PM
 */

package vistas;

import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.util.LinkedList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.CloseAction;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 *
 * @author usuario
 */
public class VistaCategoria extends javax.swing.JFrame {
    private controladores.ControladorCategoria control;

    /** Creates new form VistaCategoria */
    public VistaCategoria() {
        initComponents();
        control= new controladores.ControladorCategoria(this);
        addAction();
    }

    public void addListener(ActionListener escuchador){
        btnSalir.addActionListener(escuchador);
        btnRegistrar.addActionListener(escuchador);
        btnCancelar.addActionListener(escuchador);
    }
    
    public void mostrarMensaje(String mensaje){
        JOptionPane.showMessageDialog(new JFrame(),mensaje,"Cari Burger",JOptionPane.INFORMATION_MESSAGE);

    	
    }
    
    public void windowClosing(WindowEvent e){
		setVisible(false);
	}
    
    

    public void addAction(){
        btnSalir.setActionCommand("Salir");
        btnRegistrar.setActionCommand("Registrar");
        btnCancelar.setActionCommand("Cancelar");
    }
    
    public void limpiar(){
        txtCodigo.setText("");
        txtDescripcion.setText("");
    }

    public boolean hayVacios(){
        for (JTextField texto: getTextos()){
            if(texto.getText().equals("")){
                JOptionPane.showMessageDialog(new JFrame(),"Campos vacios","Cari Burguer",JOptionPane.INFORMATION_MESSAGE);
                return true;
            }
       }
        return false;
    }

    public boolean codigoValido(){
        try{
            if(Double.parseDouble(txtCodigo.getText())<=0){
                txtCodigo.setText("");
                JOptionPane.showMessageDialog(new JFrame(),"El codigo es invalido","Cari Burguer",JOptionPane.WARNING_MESSAGE);
                return false;
           }
       }catch(NumberFormatException ex){
           JOptionPane.showMessageDialog(new JFrame(),"El codigo es invalido","Cari Burguer",JOptionPane.WARNING_MESSAGE);
           return false;
       }
    return true;
    }

    public LinkedList<JTextField> getTextos() {
        LinkedList<JTextField> v = new LinkedList<JTextField>();
        v.add(txtCodigo);
        v.add(txtDescripcion);
        return v;
    }

    public JTextField getTxtCodigo() {
        return txtCodigo;
    }

    public JTextField getTxtDescripcion() {
        return txtDescripcion;
    }

    







     



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btnRegistrar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        txtDescripcion = new javax.swing.JTextField();
        txtCodigo = new javax.swing.JTextField();
        btnSalir = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Categorias");
        setBackground(new java.awt.Color(17, 62, 230));
        setForeground(new java.awt.Color(14, 242, 25));
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(246, 238, 238));
        jLabel1.setText("Descripcion:");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(80, 110, 100, 18);

        jLabel2.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(246, 238, 238));
        jLabel2.setText("Codigo:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(80, 50, 60, 18);

        btnRegistrar.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnRegistrar.setText("Registrar");
        getContentPane().add(btnRegistrar);
        btnRegistrar.setBounds(73, 190, 120, 30);

        btnCancelar.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnCancelar.setText("Cancelar");
        getContentPane().add(btnCancelar);
        btnCancelar.setBounds(204, 190, 120, 30);

        getContentPane().add(txtDescripcion);
        txtDescripcion.setBounds(180, 100, 110, 28);

     
        getContentPane().add(txtCodigo);
        txtCodigo.setBounds(180, 40, 110, 28);

        btnSalir.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnSalir.setText("Salir");
        getContentPane().add(btnSalir);
        btnSalir.setBounds(334, 190, 120, 30);

        jLabel3.setBackground(new java.awt.Color(20, 57, 207));
        jLabel3.setOpaque(true);
        getContentPane().add(jLabel3);
        jLabel3.setBounds(2, -2, 545, 270);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-540)/2, (screenSize.height-291)/2, 540, 291);
    }// </editor-fold>//GEN-END:initComponents


    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VistaCategoria().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnRegistrar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtDescripcion;
    // End of variables declaration//GEN-END:variables

}
